<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%
    	request.setAttribute("group", 100);
    %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录/注册</title>
<link rel="stylesheet" href="assets/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/bootstrap-theme.css">
<link rel="stylesheet" href="assets/css/login-jsp.css">
<link rel="stylesheet" type="text/css" href="js/jquery-ui.css">
<script type="text/javascript" src="js/jQuery-1.9.1.js"></script>
</head>
<body class="linear">
	<header class="navbar navbar-demo" id="top" role="banner">
		<div id="navOne" class="navbar" role="navigation">
				<div class="navbar-header">
					<button type="button" style="margin:10px 0 0 0" class="navbar-toggle" data-toggle="collapse" disabled="disabled" 
						data-target=".navbar-collapse">
						<span class="sr-only">Toggle navigation</span> <span
							class="icon-bar"></span> <span class="icon-bar"></span> <span
							class="icon-bar"></span>
					</button>
					<div class="navbar-brand"> 
						<img src="assets/img/logo_title.png" alt="">
						<h1 class="bjtu-title" style="">注册文本标注系统</h1>
					</div>
				</div>
		</div>
	</header>
	<div class="container-fluid myrow">
		<div class="row myrow">
		    <div class="col-xs-10 col-sm-10 col-md-4"><!-- col-md-offset-3 -->
		      <div class="login-panel panel panel-default">
		        <div class="panel-heading">注册</div>
		        <div class="form-horizontal">
		            <div class="form-group">
		               <label for="userid" class="col-sm-2 control-label">用户名</label>
		               <div class="col-sm-8">
		                  <input class="form-control" id="userid" placeholder="用户名" name="checkcode" type="text" autofocus="">
		               </div> 
		            </div>
		            <div class="form-group">
		               <label for="name" class="col-sm-2 control-label">姓名</label>
		               <div class="col-sm-8">
		                <input class="form-control" id="name" placeholder="姓名" name="password" type="text" value="">
		              </div>
		            </div>
		            <div class="form-group">
		              <label for="email" class="col-sm-2 control-label">邮箱</label>
		              <div class="col-sm-8">
		                <input class="form-control" id="email" placeholder="邮箱" name="checkcode" type="email" autofocus="">
		              </div>
		            </div>
		            <div class="form-group">
		              <label for="phone" class="col-sm-2 control-label">手机号</label>
		              <div class="col-sm-8">
		                <input class="form-control" id="phone" placeholder="手机号" name="checkcode" type="text" autofocus="">
		              </div>
		            </div>
		            <div class="form-group">
		              <label for="password" class="col-sm-2 control-label">密码</label>
		              <div class="col-sm-8">
		                <input class="form-control" id="password" placeholder="密码" name="checkcode" type="password" autofocus="">
		              </div>
		            </div>
		            <div class="form-group">
		              <label for="passwordConfirm" class="col-sm-2 control-label">确认密码</label>
		              <div class="col-sm-8">
		                <input class="form-control" id="passwordConfirm" placeholder="确认密码" name="checkcode" type="password" autofocus="">
		              </div>
		              </div>
		              <div class="text-center">
			               <a href="javascript:void(0);" class="btn btn-primary" id="register">注册</a>
			               <a href="javascript:void(0);" class="btn btn-primary" id="login">登录</a>
			               <button class="btn btn-primary"  id="vistor">游客</button>
		              </div>
		              <div class ="text-center">
		              <p1 id="errorRegister" style="color:red; font-size:16px">
		              </div>
		            </fieldset>
		        </div>
		      </div>
		    </div><!-- /.col-->
		    <div class="col-xs-12 col-sm-12 col-md-8  myjumb"><!-- col-md-offset-3 -->
			    <p>微信公众号文本标注系统，旨在方便用户对公众号文本类别进行标注，并帮助工作人员进行标注结果的统计。</p>
				<p>微信公众号文本标注系统，旨在方便用户对公众号文本类别进行标注，并帮助工作人员进行标注结果的统计。</p>
				<p>微信公众号文本标注系统，旨在方便用户对公众号文本类别进行标注，并帮助工作人员进行标注结果的统计。</p>
				<p>微信公众号文本标注系统，旨在方便用户对公众号文本类别进行标注，并帮助工作人员进行标注结果的统计。</p>
		    </div>
		    
	  </div>
  </div>
	<footer>
		<p class="text-center" style="margin:20px 0 20px 0">版权所有 北京交通大学交通数据挖掘实验室</p>
	</footer>

   <script type="text/javascript">		
		~function(){
			function registerbtn() {
				var id = eval(document.getElementById('userid')).value;
				var name = eval(document.getElementById('name')).value;
				var email = eval(document.getElementById('email')).value;
				var phone = eval(document.getElementById('phone')).value;
				var password = eval(document.getElementById('password')).value;
				var passwordConfirm = eval(document.getElementById('passwordConfirm')).value;
				
				if (id.length == 0 || name.length == 0 || email.length == 0
						|| phone.length == 0 || password.length == 0) {
					document.getElementById("errorRegister").innerHTML = "请确认填写每一项内容。";
				}  else if (!(/^1[3|4|5|7|8][0-9]\d{4,8}$/.test(phone))) {
					document.getElementById("errorRegister").innerHTML = "请输入正确的手机号码。";
				} else if (!(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/
						.test(email))) {
					document.getElementById("errorRegister").innerHTML = "请输入正确的邮箱。";
				}else if(password.length < 6){
					document.getElementById("errorRegister").innerHTML = "请至少输入6位密码";
				}else if(password != passwordConfirm){
					document.getElementById("errorRegister").innerHTML = "两次密码输入不一致";
				}else {
					document.getElementById("errorRegister").innerHTML = "";
					url = "./label/register.do";
					$.ajax({
						url : url,
						type : "POST",
						dataType : 'json',
						data : {
							userid : id,
							name : name,
							email : email,
							phone : phone,
							password : password
						},
						success : function(data) {
							var obj = JSON.parse(data);//转换后的JSON对象
						    if(obj.code == 0){
						    	window.location = "./label/gettext.do";
							}else if(obj.code == 400){
								if(obj.message == "UserId Illegal"){
								    document.getElementById("errorRegister").innerHTML = "用户名已存在！";
								}else{
									document.getElementById("errorRegister").innerHTML = "注册失败，请重新注册！";
								}
							}						
						}
					});

				}
			}
			$("#register").click(registerbtn);
			$("#login").click(function(){
				window.location.href = "login.jsp";
			});
			$("#vistor").click(function(){
				window.location = "./label/gettext.do";
			});
		}();
		window.onload = function(){
			document.getElementById("userid").value = "" ;
			document.getElementById("name").value = "" ;
			document.getElementById("email").value = "" ;
			document.getElementById("phone").value = "" ;			
			document.getElementById("password").value = "" ;
			document.getElementById("passwordConfirm").value = "" ;
		}
	</script>

</body>
</html>